package com.example.test.util;

import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 关闭流，释放资源
 * @Author 林文峰
 * @Date 2020/6/23 0023 13:52
 */
public class CloseUtil {
	
	/**
	 * 通用关闭流方法
	 * @Author: 林文峰 
	 * @Date 2020/6/23 0023 13:59
	 */
	public static void conClose(Object... objects){
		for (Object object : objects) {
			try {
				if (object instanceof InputStream){
					((InputStream) object).close();
				}else if (object instanceof OutputStream){
					((OutputStream) object).close();
				}else if (object instanceof XWPFDocument){
//					((XWPFDocument) object).close();
				}else if (object instanceof XWPFWordExtractor){
					((XWPFWordExtractor) object).close();
				}
			}catch (IOException i){
				i.printStackTrace();
				return;
//				throw new IOException("流关闭异常");
			}
		}
	}
}
